package org.someone.office;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.xddf.usermodel.text.FontAlignment;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
import org.apache.poi.xwpf.usermodel.TableWidthType;
import org.apache.poi.xwpf.usermodel.TextAlignment;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;
import org.apache.poi.xwpf.usermodel.XWPFStyle;
import org.apache.poi.xwpf.usermodel.XWPFStyles;
import org.apache.poi.xwpf.usermodel.XWPFTable;
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
import org.apache.poi.xwpf.usermodel.XWPFTableCell.XWPFVertAlign;
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFonts;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBody;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDocument1;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHMerge;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageMar;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPageSz;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGridCol;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblWidth;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STPageOrientation;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
import org.someone.common.DateUtil;

public class OfficeExample {
	
	private static List<Map<String,Object>> getListDatas(int size){
		List<Map<String, Object>> list = new ArrayList<>();
		for(int i=0; i<size; i++){
			Map<String, Object> data = new LinkedHashMap <>();
			data.put("序号", i);
			data.put("日期字符", DateUtil.FormatDate(DateUtil.AddDate(new Date(), -i, DateUtil.AddType_intDay)));
			data.put("日期", DateUtil.AddDate(new Date(), -i, DateUtil.AddType_intDay));
			data.put("汉字", "测试名称");
			if(i!= 8){
				data.put("浮点数", Math.random()*100.0);
			}
			list.add(data);
		}
		return list;
	}
	
	public static void TestExcel() throws IOException{
		 HashMap<String, Object> returnMap = new HashMap<>();
		    String prefix = "";
		    String yansmxPrefix = prefix + "_验收明细_";
		    String danpcmxPrefix = prefix + "_单批次明细_";
		    List<HashMap<String, Object>> yansmxQList = new ArrayList<>();
		    for (int i = 0; i < 2; i++) {
		      HashMap<String, Object> mapQ = new HashMap<>();
		      mapQ.put(yansmxPrefix+"序号", i+1);
		      mapQ.put(yansmxPrefix+"日期", "RIQ\r\n"+i);
		      mapQ.put(yansmxPrefix+"品种", "PINZ"+i);
		      mapQ.put(yansmxPrefix+"运输方式", "YUNSFS"+i);
		      mapQ.put(yansmxPrefix+"矿发量", "PIAOZ"+i);  
		      mapQ.put(yansmxPrefix+"验收量", "JINGZ"+i);  
		      mapQ.put(yansmxPrefix+"盈亏量", "KYL"+i);  
		      mapQ.put(yansmxPrefix+"途损量", "YUNS"+i);  
		      mapQ.put(yansmxPrefix+"扣减量", "KOUJL"+i);  
		      mapQ.put(yansmxPrefix+"Qnetar_mj", "REZ_MJ"+i);    
		      mapQ.put(yansmxPrefix+"Qnetar", "REZ"+i);    
		      mapQ.put(yansmxPrefix+"Aar", "AAR"+i);
		      mapQ.put(yansmxPrefix+"Vad", "VAD"+i);
		      mapQ.put(yansmxPrefix+"Mar", "MT"+i);
		      mapQ.put(yansmxPrefix+"Std", "STD"+i);
		      yansmxQList.add(mapQ);
		    }
		    //单批次明细
		    List<HashMap<String, Object>> danpcmxQList = new ArrayList<>();
		    for (int i = 0; i < 1; i++) {
		      HashMap<String, Object> mapQ = new HashMap<>();
		      mapQ.put(danpcmxPrefix+"煤矿单位", "MEIK"+i);    
		      mapQ.put(danpcmxPrefix+"发站", "FAZ"+i);  
		      mapQ.put(danpcmxPrefix+"基价", ""+i);
		      mapQ.put(danpcmxPrefix+"扣水", "KOUS"+i);
		      mapQ.put(danpcmxPrefix+"Stad", "STAD"+i);  
		      mapQ.put(danpcmxPrefix+"Mt", "MT"+i);  
		      mapQ.put(danpcmxPrefix+"Mad", "MAD"+i);  
		      mapQ.put(danpcmxPrefix+"Vdaf", "VDAF"+i);  
		      mapQ.put(danpcmxPrefix+"Aad", "AAD"+i);  
		      mapQ.put(danpcmxPrefix+"Qnetar", "QNETAR_MJ"+i);  
		      mapQ.put(danpcmxPrefix+"车数", "CHES"+i);  
		      mapQ.put(danpcmxPrefix+"货票数", "PIAOZ"+i);  
		      mapQ.put(danpcmxPrefix+"验收数", "JINGZ"+i);  
		      mapQ.put(danpcmxPrefix+"单价", "DANJ"+i);  
		      mapQ.put(danpcmxPrefix+"金额", "JINE"+i);
		      danpcmxQList.add(mapQ);
		    }
		    returnMap.put("yansmxQList", yansmxQList);
		    returnMap.put("danpcmxQList", danpcmxQList);
		
		
	  Map<String,Object> textmap = new HashMap<>();
	  String[] ss = {"0","1","2"};
	  textmap.put("0_合同量",ss);
	  textmap.put("word","kk\r\nkk");
	
	  List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
	  
	  for(int i=0, j=0, m=0; i<100; i++){
		  
		  if(i%3==0)j++;
		  if(i%7==0)m++;
	      Map<String,Object> map = new HashMap<>();
	      map.put("a","安联大厦");
	      map.put("b","阿斯蒂芬"+j);
	      map.put("c","遗鸥喷雾"+m);
	      map.put("d","就都很忙"+i);
	      map.put("e","进的农村"+i);
	      list.add(map);
	  }
	  textmap.put("cycline",list);
	  InputStream input = new FileInputStream("f:\\签名2.png");
		byte[] byt = new byte[input.available()];
		input.read(byt);
		textmap.put("签名", byt);
	  InputStream is2007 = new FileInputStream("f:\\meikjsd.xlsx" );
	  OutputStream os2007 = new FileOutputStream("f:\\write.xlsx");
	  ExcelUtil.repalceXlsx2IO(is2007,os2007,returnMap,true);
	  os2007.close();
	  is2007.close();
	}
	
	
    /**
     * 测试
     * @param args
     * @throws IOException
     * @throws InvalidFormatException 
     */
    public static void TestWord() throws IOException, InvalidFormatException {
        //替换字符map
        Map<String,Object> textmap = new HashMap<>();
        textmap.put("0_合同量","我就是^l<br>替換^p\r的字符");
        textmap.put("合同0_合同代码","我就是替換的字符");
        textmap.put("word","kkkk");
        textmap.put("4.5", 4.5);
        textmap.put("2.4", 2.4);
        textmap.put("2", 2);
        textmap.put("2.5", 2.5);
        textmap.put("4.4", 4.4);
        textmap.put("3.5", 3.5);
        textmap.put("1.8", 1.8);
        textmap.put("3", 3);
        textmap.put("2.8", 2.8);
        textmap.put("5", 5);
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        for(int i=0; i<100; i++){
            Map<String,Object> map = new HashMap<>();
            map.put("a","安联大厦");
            map.put("b","阿斯蒂芬"+i);
            map.put("c","遗鸥喷雾"+i);
            map.put("d","就都很忙"+i);
            map.put("e","进的农村"+i);
            list.add(map);
        }
        textmap.put("tabletest",list);
        List<Map<String,Object>> list2 = new ArrayList<Map<String,Object>>();
		for(int i=0; i<6; i++){
			Map<String,Object> map = new HashMap<>();
			java.util.Random rd = new java.util.Random();
			map.put("类别", "类别"+(i+1));
			map.put("系列 1", 3.4);
			map.put("系列 2", 3.9);
			map.put("系列 3", 4.4);
			list2.add(map);
		}
		textmap.put("chart", list2);
		InputStream input = new FileInputStream("f:\\签名2.png");
		byte[] byt = new byte[input.available()];
		input.read(byt);
		textmap.put("签名", byt);
        //2007+
        InputStream is2007 = new FileInputStream("f:\\read.docx" );
        OutputStream os2007 = new FileOutputStream("f:\\write.docx");
        WordUtil.repalceDocx2IO(is2007, os2007, textmap, true);
        os2007.close();
        is2007.close();
        
        InputStream tmp = new FileInputStream("f:\\write.docx" );
        OutputStream tmpp = new FileOutputStream("f:\\write.pdf");
        WordUtil.wordConverterPdf(tmp, tmpp);
        tmpp.close();
        tmp.close();
        
        
        
    }
	
    /**
     * 测试
     * @param args
     * @throws IOException
     * @throws InvalidFormatException 
     */
    public static void TestWord2PDF() throws IOException, InvalidFormatException {
        InputStream is2007 = new FileInputStream("f:\\周例会报告.docx" );
        OutputStream os2007 = new FileOutputStream("f:\\write.pdf");
        WordUtil.wordConverterPdf(is2007, os2007);
        os2007.close();
        is2007.close();
    }
    
    public static void TestPPTX() throws InvalidFormatException, IOException, XmlException{
    	Map<String,Object> paramap = new HashMap<>();
    	List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
    	Map<String,Object> map = new HashMap<>();
    	map.put("CGLX","阳光采购");
    	map.put("YSFS","公路");
    	map.put("MZ","烟煤");
    	map.put("GHDW","中电投重庆铝业国际贸易有限公司（重庆铝业国贸2100）");
    	map.put("SSSL","0.1179");
    	map.put("LF","0.37");
    	map.put("RZ","7.680");
    	map.put("RCBD","0.00");
    	list.add(map);
    	map = new HashMap<>();
    	map.put("CGLX","阳光采购");
    	map.put("YSFS","公路");
    	map.put("MZ","烟煤");
    	map.put("GHDW","宣威市泰兴商贸有限公司（泰兴公司3000）");
    	map.put("SSSL","1.086");
    	map.put("LF","0.18");
    	map.put("RZ","12.050");
    	map.put("RCBD","631.94");
    	list.add(map);
    	map = new HashMap<>();
    	map.put("CGLX","阳光采购");
    	map.put("YSFS","公路");
    	map.put("MZ","烟煤");
    	map.put("GHDW","重庆市农业生产资料（集团）有限公司(农资公司3000)");
    	map.put("SSSL","1.0534");
    	map.put("LF","0.6");
    	map.put("RZ","11.920");
    	map.put("RCBD","632.67");
    	list.add(map);
    	map = new HashMap<>();
    	map.put("CGLX","阳光采购");
    	map.put("YSFS","公路");
    	map.put("MZ","烟煤");
    	map.put("GHDW","宣威市宏鑫商贸有限公司（宏鑫公司3000）");
    	map.put("SSSL","1.5122");
    	map.put("LF","0.5");
    	map.put("RZ","12.320");
    	map.put("RCBD","644.20");
    	list.add(map);
    	map = new HashMap<>();
    	map.put("CGLX","阳光采购");
    	map.put("YSFS","公路");
    	map.put("MZ","烟煤");
    	map.put("GHDW","宣威市德胜商贸有限公司（德胜公司3000）");
    	map.put("SSSL","3.3193");
    	map.put("LF","0.09");
    	map.put("RZ","12.24");
    	map.put("RCBD","645.53");
    	list.add(map);
    	map = new HashMap<>();
    	map.put("CGLX","阳光采购");
    	map.put("YSFS","公路");
    	map.put("MZ","烟煤");
    	map.put("GHDW","宣威市必昌矿业有限公司（必昌公司3000）");
    	map.put("SSSL","2.7725");
    	map.put("LF","0.09");
    	map.put("RZ","13.08");
    	map.put("RCBD","648.37");
    	list.add(map);
    	map = new HashMap<>();
    	map.put("CGLX","阳光采购");
    	map.put("YSFS","公路");
    	map.put("MZ","烟煤");
    	map.put("GHDW","宣威市亚邦商贸有限公司（亚邦公司3000）");
    	map.put("SSSL","1.0145");
    	map.put("LF","0.16");
    	map.put("RZ","12.34");
    	map.put("RCBD","648.37");
    	list.add(map);
    	map = new HashMap<>();
    	map.put("CGLX","阳光采购");
    	map.put("YSFS","公路");
    	map.put("MZ","烟煤");
    	map.put("GHDW","宣威市德盛矿业有限公司（德盛公司3000）");
    	map.put("SSSL","2.026");
    	map.put("LF","0.14");
    	map.put("RZ","13.69");
    	map.put("RCBD","648.43");
    	list.add(map);
    	map = new HashMap<>();
    	map.put("CGLX","阳光采购");
    	map.put("YSFS","公路");
    	map.put("MZ","烟煤");
    	map.put("GHDW","宣威市银鑫煤业有限公司（银鑫公司4000）");
    	map.put("SSSL","1.0743");
    	map.put("LF","0.75");
    	map.put("RZ","17.58");
    	map.put("RCBD","696.88");
    	list.add(map);
    	paramap.put("TEST", list);
    	
//		paramap.put("变量","<我就是替換的字符>");
//		paramap.put("值", 5.5);
//		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
//		for(int i=0, j=0, m=0; i<5; i++){
//		  if(i%3==0)j++;
//		  if(i%7==0)m++;
//	      Map<String,Object> map = new HashMap<>();
//	      map.put("a","安联大厦");
//	      map.put("b","阿斯蒂芬"+j);
//	      map.put("c","遗鸥喷雾"+m);
//	      map.put("d","就都很忙"+i);
//	      map.put("e","进的农村"+i);
//	      list.add(map);
//		}
//		paramap.put("cycline",list);
//		
//		List<Map<String,Object>> list2 = new ArrayList<Map<String,Object>>();
//		for(int i=0; i<6; i++){
//			Map<String,Object> map = new HashMap<>();
//			java.util.Random rd = new java.util.Random();
//			map.put("类别", "类别\r\n"+(i+1));
//			map.put("系列 1", 3.4);
//			map.put("系列 2", 3.9);
//			map.put("系列 3", 4.4);
//			list2.add(map);
//		}
//		paramap.put("chart", list2);
//		
//		InputStream input = new FileInputStream("f:\\签名2.png");
//		byte[] byt = new byte[input.available()];
//		input.read(byt);
//		paramap.put("签名", byt);
//		paramap.put("本月", 5);
//		paramap.put("本年", 2019);
		
		InputStream is = new FileInputStream("f:\\template\\分矿采购入厂标煤单价.pptx");
		OutputStream os = new FileOutputStream("f:\\write.pptx");
		PPTUtil.replacePptx2IO(is, os, paramap);
		os.close();
		is.close();
//		input.close();
    }
    
    public static void TestWord1() throws IOException, InvalidFormatException {
    	InputStream is2007 = new FileInputStream("f:\\第28周例会报告.docx" );
        OutputStream os2007 = new FileOutputStream("f:\\周例会报告.docx");
        Map<String,Object> paramap = new HashMap<>();
        InputStream excel = new FileInputStream("f:\\运维记录.xlsx" );
        XSSFWorkbook workbook = new XSSFWorkbook(excel);
//        Date dd = new Date('2019-07-02');
        
        XSSFSheet sheet = workbook.getSheet("业务状态");
        Double dba = sheet.getRow(6).getCell(7).getNumericCellValue();
        paramap.put("工单数", dba);
        
        WordUtil.repalceDocx2IO(is2007, os2007, paramap, true);
        os2007.close();
        is2007.close();
    }
    
    
    
    public static void mergerTest() throws IOException, XmlException{
    	InputStream is = new FileInputStream("f:\\root.docx" );
    	XWPFDocument docx = new XWPFDocument(is);
    	
    	WordUtil.setPageStyleByWidth(docx, BigInteger.valueOf(27000));
    	XWPFTable tb = docx.createTable(3,3);
//    	构建Tblgrid
    	CTTblGrid ctgd = tb.getCTTbl().addNewTblGrid();
//    	设置列宽
    	ctgd.addNewGridCol().setW(BigInteger.valueOf(9000));
    	ctgd.addNewGridCol().setW(BigInteger.valueOf(9000));
    	ctgd.addNewGridCol().setW(BigInteger.valueOf(9000));
    	
    	WordUtil.setCellValue(tb.getRow(0).getCell(0), "第一");
    	WordUtil.setCellValue(tb.getRow(0).getCell(1), "第一");
    	WordUtil.setCellValue(tb.getRow(0).getCell(2), "第二");
    	WordUtil.setCellValue(tb.getRow(1).getCell(0), "第一0");
    	WordUtil.setCellValue(tb.getRow(1).getCell(1), "第一1");
    	WordUtil.setCellValue(tb.getRow(1).getCell(2), "第二");
    	WordUtil.setCellValue(tb.getRow(2).getCell(0), "a");
    	WordUtil.setCellValue(tb.getRow(2).getCell(1), "b");
    	WordUtil.setCellValue(tb.getRow(2).getCell(2), "c");
    	
//    	先行后列
    	Map<String, List<XWPFTableCell>> rowmap = WordUtil.getAutoMergerRowCells(tb, false);
    	Iterator itrow = rowmap.entrySet().iterator();
    	while(itrow.hasNext()){
    		Entry entry = (Entry) itrow.next();
    		Object obkey = entry.getKey();
    		Object obvalue = entry.getValue();
    		if(obvalue instanceof List){
    			WordUtil.mergerRowCell((List<XWPFTableCell>) obvalue);
    		}
    	}
    	Map<String, List<XWPFTableCell>> colmap = WordUtil.getAutoMergerColCells(tb);
    	Iterator itcol = colmap.entrySet().iterator();
    	while(itcol.hasNext()){
    		Entry entry = (Entry) itcol.next();
    		Object obkey = entry.getKey();
    		Object obvalue = entry.getValue();
    		if(obvalue instanceof List){
    			WordUtil.mergerColCell((List<XWPFTableCell>) obvalue);
    		}
    	}
    	OutputStream os2007 = new FileOutputStream("f:\\write.docx");
    	docx.write(os2007);
//    	OutputStream os2007 = new FileOutputStream("f:\\write.pdf");
//        WordUtil.wordConverterPdf(docx, os2007);
    	docx.close();
    	is.close();
    	os2007.close();
    }
    
    public static void testPPTMerger() throws IOException, XmlException, InvalidFormatException{
    	Map<String,Object> paramap = new HashMap<>();
		paramap.put("var","<我就是替換的字符>");
    	
    	InputStream isroot = new FileInputStream("f:\\首页.pptx" );
    	InputStream islhc = new FileInputStream("f:\\来耗存与入厂标煤单价变化趋势图.pptx");
    	InputStream isfkbd = new FileInputStream("f:\\分矿采购入厂标煤单价.pptx");
    	InputStream isclkbdbh = new FileInputStream("f:\\入厂、入炉、库存标煤单价变化趋势图.pptx");
    	InputStream isrcbdqs = new FileInputStream("f:\\入厂标单对标完成趋势图.pptx");
    	XMLSlideShow pptxroot = new XMLSlideShow(isroot);
    	XMLSlideShow pptxlhc = new XMLSlideShow(islhc);
//    	XMLSlideShow pptxfkbd = new XMLSlideShow(isfkbd);
    	XMLSlideShow pptxfkbd = PPTUtil.replacePptx(isfkbd, paramap);
    	XMLSlideShow pptxclkbdbh = new XMLSlideShow(isclkbdbh);
    	XMLSlideShow pptxrcbdqs = new XMLSlideShow(isrcbdqs);
    	
    	pptxroot.createSlide().importContent(pptxlhc.getSlides().get(0));
    	pptxroot.createSlide().importContent(pptxfkbd.getSlides().get(0));
    	pptxroot.createSlide().importContent(pptxclkbdbh.getSlides().get(0));
    	pptxroot.createSlide().importContent(pptxrcbdqs.getSlides().get(0));
    	
    	paramap.put("var","<我改变了>");
    	
    	XMLSlideShow pptxfkbd1 = PPTUtil.replacePptx(new FileInputStream("f:\\分矿采购入厂标煤单价.pptx"), paramap);
    	pptxroot.createSlide().importContent(pptxfkbd1.getSlides().get(0));
    	
    	
    	OutputStream os = new FileOutputStream("f:\\write.pptx");
    	pptxroot.write(os);
    	
    	pptxrcbdqs.close();
    	pptxclkbdbh.close();
    	pptxfkbd.close();
    	pptxlhc.close();
    	pptxroot.close();
    	
    	os.close();
    	isrcbdqs.close();
    	isclkbdbh.close();
    	isfkbd.close();
    	islhc.close();
    	isroot.close();
    }
    
    public static void copySheetsTest() throws IOException{
//    	XSSFWorkbook destWb = new XSSFWorkbook();
    	XSSFWorkbook xdestWb = new XSSFWorkbook();
//    	InputStream is = new FileInputStream("f:\\meikjsd.xlsx");
//    	XSSFWorkbook srcWb = new XSSFWorkbook(is);
//    	ExcelUtil.concatWorkbook(xdestWb, srcWb);
    	InputStream is2 = new FileInputStream("f:\\read.xlsx");
    	XSSFWorkbook srcWb2 = new XSSFWorkbook(is2);
    	ExcelUtil.concatWorkbook(xdestWb, srcWb2);
    	OutputStream os = new FileOutputStream("f:\\testcopysheets.xlsx");
    	xdestWb.write(os);
    	xdestWb.close();
//    	destWb.write(os);
//    	destWb.close();
//    	srcWb.close();
    	os.close();
//    	is.close();
    	is2.close();
    	
    }
    
    public static void writeExcelTest() throws IOException{
    	XSSFWorkbook xdestWb = new XSSFWorkbook();
    	ExcelUtil.addSheet4Datas(xdestWb, getListDatas(10), "什么什么");
    	OutputStream os = new FileOutputStream("f:\\testwrite.xlsx");
    	xdestWb.write(os);
    	xdestWb.close();
    }
    
    private static void mergeWord() throws IOException, XmlException{
    	InputStream is = new FileInputStream("f:\\测试word合并-head.docx" );
    	XWPFDocument docx = new XWPFDocument(is);
    	CTBody rootBody = docx.getDocument().getBody();
    	InputStream is1 = new FileInputStream("f:\\测试word合并-part1.docx" );
    	XWPFDocument docx1 = new XWPFDocument(is1);
    	CTBody part1Body = docx1.getDocument().getBody();
    	InputStream is2 = new FileInputStream("f:\\测试word合并-part2.docx" );
    	XWPFDocument docx2 = new XWPFDocument(is2);
    	
    	WordUtil.appendWord(docx, docx1);
    	WordUtil.appendWord(docx, docx2);
	    OutputStream os2007 = new FileOutputStream("f:\\write合并.docx");
    	docx.write(os2007);
    	os2007.close();
    	is.close();
    	is1.close();
    	is2.close();
    }
    
	public static void main(String[] args) throws IOException, InvalidFormatException, XmlException{
//		TestExcel();
//		TestWord();
//		TestWord1();
//		TestWord2PDF();
//		TestPPTX();
//		mergerTest();
//		testPPTMerger();
//		copySheetsTest();
//		writeExcelTest();
		mergeWord();
	}
}
